package com.enjoy.concurrent.ch9;

import lombok.extern.slf4j.Slf4j;

/**
 * -Xint 关闭即时编译
 */
@Slf4j
public class VisibilityTest {

    private boolean flag = true;

    private int count = 0;

    private void refresh() {
        this.flag = false;

        log.info("flag="+ false +",count="+count+"");
    }

    private void load() {
        while (flag) {
            count++;
        }
        log.info("跳出循环:count="+count+"");
    }

    public static void main(String[] args) throws InterruptedException {
        VisibilityTest test = new VisibilityTest();

        new Thread(test::load, "t1").start();

        Thread.sleep(1000);

        new Thread(test::refresh, "t2").start();


    }
}
